'''
FastAPI 站在以下巨人的肩膀之上：
Starlette 负责 web 部分。
Pydantic 负责数据部分。

pip install fastapi

我们有可能还会需要一个 ASGI 服务器，可以使用Uvicorn

pip install uvicorn

uvicorn main:app --reload

http://127.0.0.1:8000/docs

http://127.0.0.1:8000/redoc
'''

from typing import Union

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
async def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

@app.get("/users/me")
async def read_user_me():
    return {"user_id": "the current user"}

@app.get("/users/{user_id}")
async def read_user(user_id: str):
    return {"user_id": user_id}

# if you redefin a path operation, only the first one will be used. 
@app.get("/users")
async def read_users():
    return ["Rick", "Morty"]

@app.get("/users")
async def read_users2():
    return ["Bean", "Elfo"]
